﻿using System.Collections.Generic;
using System.Linq;
using Ymatou.Evaluate.Buyer.Model.Dto;
using Ymatou.Evaluate.Common;
using Ymatou.Evaluate.Entity;

namespace Ymatou.Evaluate.Service.Buyer.Extensions
{
    public static class EvaluateExt
    {
        public static List<ProductEvaluateDetail> MapProductEvaluate(this IEnumerable<EvaluateProduct> list,
            List<EvaluateImgs> imgs, List<EvaluateReply> replies)
        {
            return list.Select(ep => new ProductEvaluateDetail
            {
                ProdEvalId = ep.ProdEvalId,
                BuyerId = ep.BuyerId,
                Score = ep.Score,
                CatalogDesc = ep.CatalogDesc,
                Comments = ep.Comments,
                EvalTime = ep.ProdEvalTime,
                LongEvalTime = ep.ProdEvalTime.DateTime2LongTime(),
                IsSensitive = ep.IsSensitive,
                Imgs =
                    imgs != null && imgs.Any()
                        ? imgs.Where(i => i.ProdEvalId == ep.ProdEvalId).Select(i => i.ImgUrl).ToList()
                        : null,
                Reply =
                    replies != null && replies.Any(r => r.ProdEvalId == ep.ProdEvalId)
                        ? new List<string> {replies.FirstOrDefault(r => r.ProdEvalId == ep.ProdEvalId).Reply}
                        : null
            }).ToList();
        }
    }
}